#ifndef PKGMGR_H
#define PKGMGR_H

#include "lib.h"
#include "hashtable.h"
using namespace Library;

#include "packagemanagement.h"
using namespace PackageManagement;

#ifdef CASEXE
#	include "casexe.h"
#else
	class CApp;
	typedef CApp* pCApp;
#endif

class PathName;
class ZipFile;

namespace PackageManagement
{

class PackageMgr
{
	public:
					PackageMgr(pCApp app);
					~PackageMgr();

		bool8		loadList(const String& filename);
		bool8		saveList();

		bool8		installRSync(pPackage package, int32* errCode=0, bool8 showMessage = true);
		bool8		install(pPackage package, const PathName & zipFilename);
		void		uninstall(pPackage package);

		pPackage 	find(const String& packageName);
		pPackage 	findLobby();
		pPackage 	findCashier();

		bool8		addPackage(pPackage package);
		bool8		removePackage(pPackage package);

		bool8		addFile(const String& filename);
		bool8		removeFile(const String& filename);

		uint32		packageCount();

		HashTableIterator<pPackage> *	iterator();
		HashTableIterator<int32*> *		iterateFiles();

		bool8		installRSyncGame(pPackage package, int32* errCode=0);
		bool8		installGame(pPackage package, const PathName & zipFilename);

	protected:

		void		installGameHelp(pPackage package);

		bool8		installRSyncLobby(pPackage package, bool8 showMessage);
		bool8		installLobby(pPackage package, const PathName &);

		bool8		unzipPackage(ZipFile &, PathName &);

		bool8		unzipLbyInst();
		bool8		copyLbyInst();

	protected:
		pCApp		m_app;
		String		m_filename;

		HashTable<pPackage> *	m_packages;
		HashTable<int32*> *	m_files;
};

}; // namespace PackageManagement

#endif
